﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Bll;
using AspNetCs.Model;
using AspNetCs.Common;

public partial class Master_Admin_AddVideo : Admin_BasePage
{

    private int isUpdate = 0;
    private int id = 0;

    protected VideoModel model = new VideoModel();
    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();
        if (!IsPostBack)
        {
            id = StringHelper.isNumber_int(Request["id"]);
            isUpdate = StringHelper.isNumber_int(Request["isUpdate"]);
            ViewState["id"] = id;
            ViewState["isUpdate"] = isUpdate;
            if (isUpdate == 1)
            {
                model = Video_BLL.CreateNew.GetModel("id=" + this.id);
                txtDescription.Text = model.Description;
                txtPic.Text = model.Pic;
                txtTitle.Text = model.Title;
                TextBox2.Text = model.Address1;
                TextBox3.Text = model.Address2;
                TextBox4.Text = model.Address3;
                TextBox5.Text = model.Address4;
                TextBox6.Text = model.Address5;
            }
            else
            {
                model.VideoType = "国外电影";
            }
        }
        else
        { 
            if(ViewState["id"]!=null)
            {
                id = StringHelper.isNumber_int(ViewState["id"].ToString());
            }

            if(ViewState["isUpdate"]!=null)
            {
                isUpdate = StringHelper.isNumber_int(ViewState["isUpdate"].ToString());
            }
        }
        if (isUpdate == 1)
        {
            lblAddVideoTip.Text = "修改视频";
            btnSubmit.Visible = false;
            Button1.Visible = true;
        }
        else
        {
            btnSubmit.Visible = true;
            Button1.Visible = false;
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Add();
        ResultStr("Admin_ManageVideo.aspx", "添加成功!");
    }

    public void Add()
    {
        VideoModel model = new VideoModel();
        model.Address1 = TextBox2.Text;
        model.Address2 = TextBox3.Text;
        model.Address3 = TextBox4.Text;
        model.Address4 = TextBox5.Text;
        model.Address5 = TextBox6.Text;
        model.Description = txtDescription.Text;
        model.Pic = txtPic.Text;
        model.Title = txtTitle.Text;
        model.VideoType = Request["selVideoType"];
        Video_BLL.CreateNew.Add(model);
    }


    public void Update()
    {
        VideoModel model = new VideoModel();
        model.Address1 = TextBox2.Text;
        model.Address2 = TextBox3.Text;
        model.Address3 = TextBox4.Text;
        model.Address4 = TextBox5.Text;
        model.Address5 = TextBox6.Text;
        model.Description = txtDescription.Text;
        model.Pic = txtPic.Text;
        model.Title = txtTitle.Text;
        model.VideoType = Request["selVideoType"];
        model.Id = this.id;
        Video_BLL.CreateNew.Update(model);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Update();
        ResultStr("Admin_ManageVideo.aspx", "修改成功!");
    }
}
